package br.ufpe.cin.camid.remote.infrastructure.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ServerManager 
{
	private int port = 15000;
	
	private ServerSocket serverSocket;
	
	private ExecutorService executor;
	
	public ServerManager(){
		
	}
	
	public void start()
	{
		try {
			executor = Executors.newCachedThreadPool();
			serverSocket = new ServerSocket(port);
			while(true)
			{
				Socket socket = serverSocket.accept();
				ServerAcceptor acceptor = new ServerAcceptor(socket);
				executor.execute(acceptor);
			}
		} catch (IOException e) {
			throw new CamidServerException(e);
		}
	}
	
}
